<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>风味-修改密码</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/personCenterPublic.css"/>
		<script src="js/jquery-2.1.0.js"></script>
		<style type="text/css">
		form{margin-top: 50%;}
			input{width: 100%;height: 50px;background: white;border: 1px solid #FFCC33;}
			input[type='button']{background: #FFCC33;border: none;color: white;font-family: "微软雅黑";font-size: 16px;letter-spacing: 5px;margin-top: 30px;}
			span{width: 200px;height: 30px;font-family: "微软雅黑";font-size: 14px;}
		</style>
		<script>
			$(function(){
				var str=location.href; //获取本页url地址
				var arr=str.split("?");
				var str1 = arr[1];
				var userIdString = str1.split("=")[1];
				var userId = parseInt(userIdString);
//            console.log(userId);
				var pswBtn = $("#submitePwd");
//            点击事件，点击后开始向后台提交数据
				pswBtn.click(function(){
					var userPassword = $("#newPwd2").val();
//					console.log(userPassword+">>>>>"+userId);
					$.ajax("/fengwei/user/update",{
						type:"post",
						data:{
							'userId':userId,
							'userPassword':userPassword
						},
						success:function(){
							alert(1);
//							修改成功--返回个人中心页面
							window.location.href = "personInfo.html?userId="+userId+"";
						},
						error:function(){
							alert(0);
						}
					})
				})
			})
		</script>
	</head>
	<body>
		<div id="back">
			<a href="originPwd.html"><&nbsp;返回确认密码</a>
		</div>
		<form action="" method="post">
			<input type="password" name="newPwd" id="newPwd" placeholder="请输入新密码" onblur="validateEmpty()"/>
			<input type="password" name="newPwd2" id="newPwd2"  placeholder="请确认密码" onblur="validaterepeat()"/>
			<span></span>
			<input type="button" value="提交" id="submitePwd"/>
			<!-- hbl---删掉提交里面的onclick方法--改为js控制-->
		</form>
		<script type="text/javascript">
			function validateEmpty(){//验证新密码是否可用
	 			var again_pwd=document.getElementById('newPwd');
	 			var again_pwd_span=document.getElementsByTagName('span')[0];
            	if(again_pwd.value!=""){
                again_pwd_span.innerHTML="<font color='#21dcdd'>密码可用!</font>";
            	}else{
                again_pwd_span.innerHTML="<font color='red'>输入内容为空！</font>";
            }
        }
			
			function validaterepeat(){//验证密码是否与第一次一致
			var sub_button=document.getElementById('submitePwd');
            var srcelement=document.getElementById("newPwd");
            var deselement=document.getElementById("newPwd2");
            var msgelement=document.getElementsByTagName('span')[0];
            if(srcelement.value==deselement.value&&srcelement.value!=""&&deselement.value!=""){
                msgelement.innerHTML="<font color='#21dcdd'>密码相符！</font>";
                 sub_button.disabled=false;
            }else{

                msgelement.innerHTML="<font color='red'>两次输入密码不相符！</font>";
                sub_button.disabled=true;
            }
            
        }
		</script>
	</body>
</html>
